package com.zj.fx.service.info;

import java.util.List;
import java.util.Arrays;

import com.zj.fx.mapper.info.InfoTargetMapper;
import com.zj.fx.model.info.InfoSupplyExample;
import com.zj.fx.model.info.InfoTarget;
import com.zj.fx.model.info.InfoTargetExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.zj.fx.common.base.BaseService;
import com.zj.fx.common.support.ConvertUtil;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.util.SnowflakeIdWorker;
import com.zj.fx.util.StringUtils;

/**
 * 管理提升指标 InfoTargetService
 *
 * @author SQL_自动生成
 * @Title: InfoTargetService.java 
 * @Package com.zj.fx.service 
 * @email ${email}
 * @date 2023-06-08 16:48:12  
 **/
@Service
public class InfoTargetService implements BaseService<InfoTarget, InfoTargetExample> {
    @Autowired
    private InfoTargetMapper infoTargetMapper;


    /**
     * 分页查询
     *
     * @param
     * @param
     * @return
     */
    public PageInfo<InfoTarget> list(Tablepar tablepar, InfoTarget infoTarget) {
        InfoTargetExample testExample = new InfoTargetExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(infoTarget);
        }
        //表格排序
        //if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        //}else{
        //	testExample.setOrderByClause("id ASC");
        //}
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<InfoTarget> list = infoTargetMapper.selectByExample(testExample);
        PageInfo<InfoTarget> pageInfo = new PageInfo<InfoTarget>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        List<String> lista = ConvertUtil.toListStrArray(ids);
        InfoTargetExample example = new InfoTargetExample();
        example.createCriteria().andIdIn(lista);
        return infoTargetMapper.deleteByExample(example);


    }


    @Override
    public InfoTarget selectByPrimaryKey(String id) {

        return infoTargetMapper.selectByPrimaryKey(id);

    }


    @Override
    public int updateByPrimaryKeySelective(InfoTarget record) {
        return infoTargetMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(InfoTarget record) {

        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());


        return infoTargetMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(InfoTarget record, InfoTargetExample example) {

        return infoTargetMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(InfoTarget record, InfoTargetExample example) {

        return infoTargetMapper.updateByExample(record, example);
    }

    @Override
    public List<InfoTarget> selectByExample(InfoTargetExample example) {

        return infoTargetMapper.selectByExample(example);
    }


    @Override
    public long countByExample(InfoTargetExample example) {

        return infoTargetMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(InfoTargetExample example) {

        return infoTargetMapper.deleteByExample(example);
    }

    public List<InfoTarget> selectAll() {
        InfoTargetExample infoTargetExample = new InfoTargetExample();
        InfoTargetExample.Criteria criteria = infoTargetExample.createCriteria();
        criteria.andIdIsNotNull();
        return infoTargetMapper.selectByExample(infoTargetExample);
    }
}
